package com.scsj.supermarket.view.activity.businesscirclemodel;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.scsj.supermarket.R;
import com.scsj.supermarket.base.QueryTradeDetailBase;
import com.scsj.supermarket.bean.QueryTradeDetailBean;
import com.scsj.supermarket.presenter.QueryTradeDetailPresenter;
import com.scsj.supermarket.utils.BaiduMapHelper;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;

import okhttp3.RequestBody;

/**
 * 商圈详情
 */
public class BusinessCircleDetailActivity extends BaseActivity implements QueryTradeDetailBase.IView{
    private QueryTradeDetailPresenter queryTradeDetailPresenter;
    private String tradeId;
    //地图控件
    private MapView mapView;
    private BaiduMap baiduMap;

    private TextView tradeNameTv;
    private TextView tradeNoticeTv;
    private TextView tradeShopNumTv;
    private TextView tradeAddressTv;
    private TextView tradePhoneTv;
    private TextView tradeMonthSaleTv;
    private ImageView tradeHeadImg;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_business_circle_detail);
        initView();
        initData();
        initListener();
    }

    @Override
    protected void initView() {
        queryTradeDetailPresenter= new QueryTradeDetailPresenter(this);
        mapView= findViewById(R.id.trade_area_detail_mv);

        tradeNameTv= findViewById(R.id.trade_name);
        tradeNoticeTv= findViewById(R.id.notice_tv);
        tradeShopNumTv= findViewById(R.id.shop_num_tv);
        tradeAddressTv= findViewById(R.id.adress_tv);
        tradePhoneTv= findViewById(R.id.phone_tv);
        tradeMonthSaleTv= findViewById(R.id.month_sales_tv);
        tradeHeadImg= findViewById(R.id.head_fab);


    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        BaiduMapHelper
                .getInstance()
                .init(mapView)
                .params(this)
                .showLocation();
        tradeId= getIntent().getStringExtra("tradeId");

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", tradeId);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), jsonObject.toString());
        queryTradeDetailPresenter.deliverData(body);

    }

    @Override
    public void showSuccessMsg(String s, QueryTradeDetailBean queryTradeDetailBean) {
        //数据设置成功之后开始设置数据

        if (queryTradeDetailBean.isSuccess()){
            //公告
            String shopNotice= queryTradeDetailBean.getData().getNotice();
            tradeNoticeTv.setText(shopNotice+"");
            //商圈名字
            String shopName= queryTradeDetailBean.getData().getName();
            tradeNameTv.setText(shopName+"");
            //店铺数量
            int shopNum= queryTradeDetailBean.getData().getStoreNum();
            tradeShopNumTv.setText(shopNum+"");
            //销量
            int saleNum= queryTradeDetailBean.getData().getOrderNum();
            tradeMonthSaleTv.setText(saleNum+"");
            //商圈中心地址
            String tradeAddress= queryTradeDetailBean.getData().getAddress();
            tradeAddressTv.setText(tradeAddress+"");
            //圈主电话
            String tradeMasterPhone= queryTradeDetailBean.getData().getPhone();
            tradePhoneTv.setText(tradeMasterPhone+"");
            //圈主头像
            String tradeUrl= (String) queryTradeDetailBean.getData().getTradeAreaImg();
            Glide.with(mContext).
                    load(tradeUrl).
                    diskCacheStrategy(DiskCacheStrategy.RESULT).
                    thumbnail(0.5f).
                    placeholder(R.drawable.ic_launcher_background).
                    priority(Priority.LOW).
                    error(R.drawable.ic_launcher_background).
                    fallback(R.drawable.ic_launcher_background).
                    into(tradeHeadImg);

        }
    }

    @Override
    public void showErrorMsg(String s) {
    }
}
